﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Taurus.Components
{
    /// <summary>
    /// 组件接口
    /// 2009-12-17 
    /// 吴鸣震
    /// modify:
    ///         将接口改为抽象类，提供了初始化组件事件
    /// </summary>
    public abstract class Component
    {
        public event EventHandler StartInit;
        public event EventHandler EndInit;
        public event EventHandler<MsgEventArgs> NewMessage;
        /// <summary>
        /// 初始化组件
        /// </summary>
        virtual protected void Init()
        {
        }

        public void SendMessage(string msg)
        {
            if (NewMessage!=null)
            {
                NewMessage(this, new MsgEventArgs() { Msg = msg });
            }
        }
        public void InitComponent()
        {
            if (StartInit != null)
            {
                StartInit(this, null);
            }
            Init();
            if (EndInit != null)
            {
                EndInit(this, null);
            }
        }
         
        abstract public string Name { get; }

        abstract public string Version { get; }
        /// <summary>
        /// 组件唯一标识
        /// </summary>
        abstract public string Unique { get; }

        /// <summary>
        /// 子组件集合
        /// </summary>
        virtual public List<Component> Components { get; set; }

        /// <summary>
        /// 返回组件可视化操作面
        /// 如果返回null表示没有用户操作界面
        /// 将不对对应菜单click事件做程序绑定界面操作
        /// </summary>
        abstract public UserControl GetUI();
    }
    
}
